﻿<%@ WebHandler Language="C#" Class="GetImageInCategory" %>

using System;
using System.Web;
using Ext.Net;
using NOAH.CMS.Repository;
using System.Collections.Generic;

public class GetImageInCategory : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/json";

        int start = 0;
        int limit = 0;
        int count = 0;
        int categoryId = 0;

        start = int.Parse(context.Request.QueryString["start"].ToString());
        limit = int.Parse(context.Request.QueryString["limit"].ToString());
        int.TryParse(context.Request.QueryString["categoryId"].ToString(), out  categoryId);

        if (categoryId > 0)
        {
            List<NOAH.CMS.Repository.Image> data = new ImageRepository().GetImageInCategory(categoryId);
            context.Response.Write(string.Format("{{totalCount:{1},'imageInCate':{0}}}", JSON.Serialize(data), count));
        }
        else
        {
            List<NOAH.CMS.Repository.Image> data = new ImageRepository().GetAll();
            context.Response.Write(string.Format("{{totalCount:{1},'imageInCate':{0}}}", JSON.Serialize(data), data.Count));
        }
    }

    public bool IsReusable
    {
        get
        {
            return true;
        }
    }

}